package com.woniuxy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.annotation.Resource;

/**
 * Swagger2Config设置
 */
@Configuration //标记配置类
@EnableSwagger2 //开启在线接口文档
public class Swagger2Config {
    @Resource
    private  SwaggerConfigProperties scp;

    /**
     * 添加摘要信息(Docket)
     */
    @Bean
    public Docket controllerApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title(scp.getTitle())
                        .description(scp.getDesc())
                        .contact(new Contact(scp.getContact().getName(), scp.getContact().getUrl(), scp.getContact().getEmail()))
                        .version(scp.getVersion())
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage(scp.getBasePackage()))
                .paths(PathSelectors.any())
                .build();
    }
}
